{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> start QUANTAXIS\n",
      "QUANTAXIS>> Selecting the Best Server IP of TDX\n",
      "QUANTAXIS>> === The BEST SERVER ===\n",
      " stock_ip 180.153.39.51 future_ip 61.152.107.141\n",
      "QUANTAXIS>> Welcome to QUANTAXIS, the Version is 1.0.0\n",
      "QUANTAXIS>>  \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      "  ``########`````##````````##``````````##`````````####````````##```##########````````#``````##``````###```##`````######`` \n",
      "  `##``````## ```##````````##`````````####````````##`##```````##```````##```````````###``````##````##`````##```##`````##` \n",
      "  ##````````##```##````````##````````##`##````````##``##``````##```````##``````````####```````#```##``````##```##``````## \n",
      "  ##````````##```##````````##```````##```##```````##```##`````##```````##`````````##`##```````##`##```````##````##``````` \n",
      "  ##````````##```##````````##``````##`````##``````##````##````##```````##````````##``###```````###````````##`````##`````` \n",
      "  ##````````##```##````````##``````##``````##`````##`````##```##```````##```````##````##```````###````````##``````###```` \n",
      "  ##````````##```##````````##`````##````````##````##``````##``##```````##``````##``````##`````##`##```````##````````##``` \n",
      "  ##````````##```##````````##````#############````##```````##`##```````##`````###########`````##``##``````##`````````##`` \n",
      "  ###```````##```##````````##```##```````````##```##```````##`##```````##````##`````````##```##```##``````##```##`````##` \n",
      "  `##``````###````##``````###``##`````````````##``##````````####```````##```##``````````##``###````##`````##````##`````## \n",
      "  ``#########``````########```##``````````````###`##``````````##```````##``##````````````##`##``````##````##`````##````## \n",
      "  ````````#####`````````````````````````````````````````````````````````````````````````````````````````````````````####` \n",
      "  ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      "  ``````````````````````````Copyright``yutiansut``2017``````QUANTITATIVE FINANCIAL FRAMEWORK````````````````````````````` \n",
      "  ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " \n"
     ]
    }
   ],
   "source": [
    "import QUANTAXIS as QA\n",
    "import random\n",
    "market = QA.QA_Market()\n",
    "user = QA.QA_Portfolio()\n",
    "# 创建两个account\n",
    "# 这里是创建一个资产组合,然后在组合里面创建两个account  你可以想象成股票里面的两个策略账户\n",
    "# 然后返回的是这个账户的id\n",
    "a_1 = user.new_account()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account Acc_5gBMbRPI>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_MARKET with ['backtest'] Broker >\n",
      "===== SETTLED None =====< QA_Order datetime:2017-01-03 09:31:00 code:000007 price:26.1 towards:1 btype:stock_cn order_id:Order_3Rg6u9PY account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "===== SETTLED None =====\n",
      "0\n",
      "0\n",
      "0\n",
      "1000.0\n",
      "===== SETTLED None =====< QA_Order datetime:2017-01-05 09:31:00 code:000007 price:26.24 towards:-1 btype:stock_cn order_id:Order_ckyKHpvZ account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "0\n",
      "0\n",
      "0\n",
      "0.0\n",
      "===== SETTLED None =====\n",
      "0< QA_Order datetime:2017-01-09 09:31:00 code:000001 price:9.15 towards:1 btype:stock_cn order_id:Order_1U83YHJL account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "0\n",
      "0.0\n",
      "===== SETTLED None =====\n",
      "0< QA_Order datetime:2017-01-10 09:31:00 code:000001 price:9.15 towards:1 btype:stock_cn order_id:Order_1FE7rxXC account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "0\n",
      "0.0\n",
      "===== SETTLED None =====\n",
      "2000.0\n",
      "0< QA_Order datetime:2017-01-11 09:31:00 code:000001 price:9.14 towards:-1 btype:stock_cn order_id:Order_T5XO1nHW account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "0.0< QA_Order datetime:2017-01-11 09:31:00 code:000004 price:42.45 towards:1 btype:stock_cn order_id:Order_pog7K9F1 account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "===== SETTLED None =====\n",
      "1000.0\n",
      "0\n",
      "< QA_Order datetime:2017-01-12 09:31:00 code:000001 price:9.15 towards:-1 btype:stock_cn order_id:Order_W06o9Ilz account:Acc_5gBMbRPI status:300 >\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n",
      "QUANTAXIS>> code 000002 date 2017-01-12 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000.0\n",
      "0.0< QA_Order datetime:2017-01-12 09:31:00 code:000004 price:42.05 towards:-1 btype:stock_cn order_id:Order_VGLT1B9e account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "===== SETTLED None =====\n",
      "0.0\n",
      "0\n",
      "0.0\n",
      "< QA_Order datetime:2017-01-13 09:31:00 code:000007 price:23.81 towards:1 btype:stock_cn order_id:Order_GUiOhWtV account:Acc_5gBMbRPI status:300 >===== SETTLED None =====\n",
      "\n",
      "0.0\n",
      "0.0< QA_Order datetime:2017-01-16 09:31:00 code:000002 price:21.0 towards:1 btype:stock_cn order_id:Order_59tlRFmb account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "1000.0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n",
      "QUANTAXIS>> code 000007 date 2017-01-16 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "0.0\n",
      "1000.0\n",
      "< QA_Order datetime:2017-01-17 09:31:00 code:000002 price:20.8 towards:-1 btype:stock_cn order_id:Order_lqFE27Lx account:Acc_5gBMbRPI status:300 >1000.0\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_Order datetime:2017-01-17 09:31:00 code:000004 price:37.37 towards:1 btype:stock_cn order_id:Order_5pKx0uSo account:Acc_5gBMbRPI status:300 >"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> code 000007 date 2017-01-17 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "0.0< QA_Order datetime:2017-01-18 09:31:00 code:000001 price:9.17 towards:1 btype:stock_cn order_id:Order_wlNL0j1f account:Acc_5gBMbRPI status:300 >\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_Order datetime:2017-01-18 09:31:00 code:000004 price:37.15 towards:1 btype:stock_cn order_id:Order_gDME90JG account:Acc_5gBMbRPI status:300 >"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> code 000007 date 2017-01-18 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "1000.0\n",
      "0.0< QA_Order datetime:2017-01-19 09:31:00 code:000001 price:9.18 towards:-1 btype:stock_cn order_id:Order_T9qMbBfh account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "1000.0\n",
      "< QA_Order datetime:2017-01-19 09:31:00 code:000004 price:35.69 towards:1 btype:stock_cn order_id:Order_pfGqWxQy account:Acc_5gBMbRPI status:300 >\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n",
      "QUANTAXIS>> code 000007 date 2017-01-19 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "0.0\n",
      "0.0\n",
      "3000.0\n",
      "1000.0< QA_Order datetime:2017-01-20 09:31:00 code:000004 price:36.48 towards:-1 btype:stock_cn order_id:Order_YMlRe6aZ account:Acc_5gBMbRPI status:300 >\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n",
      "QUANTAXIS>> code 000007 date 2017-01-20 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "0.0\n",
      "2000.0< QA_Order datetime:2017-01-23 09:31:00 code:000002 price:20.74 towards:1 btype:stock_cn order_id:Order_6ZhPaDTi account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "1000.0\n",
      "< QA_Order datetime:2017-01-23 09:31:00 code:000004 price:37.56 towards:-1 btype:stock_cn order_id:Order_GopaSdIm account:Acc_5gBMbRPI status:300 >\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n",
      "QUANTAXIS>> code 000007 date 2017-01-23 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "1000.0< QA_Order datetime:2017-01-24 09:31:00 code:000001 price:9.27 towards:1 btype:stock_cn order_id:Order_fcPZKAbI account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "1000.0\n",
      "< QA_Order datetime:2017-01-24 09:31:00 code:000002 price:20.69 towards:-1 btype:stock_cn order_id:Order_LhqpcEaN account:Acc_5gBMbRPI status:300 >\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_Order datetime:2017-01-24 09:31:00 code:000004 price:38.63 towards:-1 btype:stock_cn order_id:Order_KW0FMjSA account:Acc_5gBMbRPI status:300 >"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> code 000007 date 2017-01-24 price None order_model close amount_model by_amount"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "1000.0\n",
      "0.0< QA_Order datetime:2017-01-25 09:31:00 code:000001 price:9.26 towards:-1 btype:stock_cn order_id:Order_59AlaEgw account:Acc_5gBMbRPI status:300 >\n",
      "\n",
      "1000.0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_Order datetime:2017-01-25 09:31:00 code:000004 price:38.25 towards:1 btype:stock_cn order_id:Order_S3M0cJmV account:Acc_5gBMbRPI status:300 >"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> code 000007 date 2017-01-25 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "0.0\n",
      "0.0\n",
      "1000.0\n",
      "< QA_Order datetime:2017-01-26 09:31:00 code:000004 price:38.29 towards:-1 btype:stock_cn order_id:Order_o0x8U143 account:Acc_5gBMbRPI status:300 >"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "QUANTAXIS>> code 000007 date 2017-01-26 price None order_model close amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "[['2017-01-03 09:31:00', '000007', 26.1, 1000.0, 'Order_3Rg6u9PY', 'Trade_QxUTrVs2', 39.150000000000006, 0.0], ['2017-01-05 09:31:00', '000007', 26.24, -1000.0, 'Order_ckyKHpvZ', 'Trade_Mv40CGKI', 39.36, 26.24], ['2017-01-09 09:31:00', '000001', 9.15, 1000.0, 'Order_1U83YHJL', 'Trade_gj487URw', 13.725000000000001, 0.0], ['2017-01-10 09:31:00', '000001', 9.15, 1000.0, 'Order_1FE7rxXC', 'Trade_XUCSG6iE', 13.725000000000001, 0.0], ['2017-01-11 09:31:00', '000001', 9.14, -1000.0, 'Order_T5XO1nHW', 'Trade_Zc0PGizg', 13.71, 9.14], ['2017-01-11 09:31:00', '000004', 42.45, 1000.0, 'Order_pog7K9F1', 'Trade_JHay7AR5', 63.67500000000001, 0.0], ['2017-01-12 09:31:00', '000001', 9.15, -1000.0, 'Order_W06o9Ilz', 'Trade_iraNkGeX', 13.725000000000001, 9.15], ['2017-01-12 09:31:00', '000004', 42.05, -1000.0, 'Order_VGLT1B9e', 'Trade_FM0K8E1s', 63.07499999999999, 42.05], ['2017-01-13 09:31:00', '000007', 23.81, 1000.0, 'Order_GUiOhWtV', 'Trade_qyfrQO98', 35.714999999999996, 0.0], ['2017-01-16 09:31:00', '000002', 21.0, 1000.0, 'Order_59tlRFmb', 'Trade_rKRw4NSC', 31.5, 0.0], ['2017-01-17 09:31:00', '000002', 20.8, -1000.0, 'Order_lqFE27Lx', 'Trade_O3hN6fpx', 31.200000000000003, 20.800000000000004], ['2017-01-17 09:31:00', '000004', 37.37, 1000.0, 'Order_5pKx0uSo', 'Trade_oDJr93xf', 56.055, 0.0], ['2017-01-18 09:31:00', '000001', 9.17, 1000.0, 'Order_wlNL0j1f', 'Trade_PsVcY7C2', 13.754999999999999, 0.0], ['2017-01-18 09:31:00', '000004', 37.15, 1000.0, 'Order_gDME90JG', 'Trade_KNeEQUWH', 55.724999999999994, 0.0], ['2017-01-19 09:31:00', '000001', 9.18, -1000.0, 'Order_T9qMbBfh', 'Trade_Jvem2dsj', 13.77, 9.180000000000001], ['2017-01-19 09:31:00', '000004', 35.69, 1000.0, 'Order_pfGqWxQy', 'Trade_7fvEs2tO', 53.535, 0.0], ['2017-01-20 09:31:00', '000004', 36.48, -1000.0, 'Order_YMlRe6aZ', 'Trade_BRjrq1sa', 54.72, 36.48], ['2017-01-23 09:31:00', '000002', 20.74, 1000.0, 'Order_6ZhPaDTi', 'Trade_ZnlUfDxM', 31.11, 0.0], ['2017-01-23 09:31:00', '000004', 37.56, -1000.0, 'Order_GopaSdIm', 'Trade_fw1cDdT4', 56.34, 37.56], ['2017-01-24 09:31:00', '000001', 9.27, 1000.0, 'Order_fcPZKAbI', 'Trade_NA96r0IQ', 13.905, 0.0], ['2017-01-24 09:31:00', '000002', 20.69, -1000.0, 'Order_LhqpcEaN', 'Trade_xUCmrLia', 31.035000000000004, 20.69], ['2017-01-24 09:31:00', '000004', 38.63, -1000.0, 'Order_KW0FMjSA', 'Trade_YGKZ2k7o', 57.945, 38.63], ['2017-01-25 09:31:00', '000001', 9.26, -1000.0, 'Order_59AlaEgw', 'Trade_sjVLtcdY', 13.889999999999999, 9.26], ['2017-01-25 09:31:00', '000004', 38.25, 1000.0, 'Order_S3M0cJmV', 'Trade_N2dHZG9o', 57.375, 0.0], ['2017-01-26 09:31:00', '000004', 38.29, -1000.0, 'Order_o0x8U143', 'Trade_JCPUeGtq', 57.435, 38.29]]\n",
      "[1000000, 973860.85, 1000061.49, 990897.765, 981734.04, 990860.3300000001, 948346.655, 957482.93, 999469.8550000001, 975624.1400000001, 954592.6400000001, 975361.4400000002, 937935.3850000001, 928751.6300000001, 891545.9050000001, 900712.1350000001, 864968.6000000001, 901393.8800000001, 880622.7700000001, 918126.4300000002, 908842.5250000001, 929501.4900000001, 968073.5450000002, 977319.6550000001, 939012.2800000001, 977244.8450000001]\n",
      "977244.8450000001\n",
      "               datetime    code  price  amount        order_id  \\\n",
      "0   2017-01-03 09:31:00  000007  26.10  1000.0  Order_3Rg6u9PY   \n",
      "1   2017-01-05 09:31:00  000007  26.24 -1000.0  Order_ckyKHpvZ   \n",
      "2   2017-01-09 09:31:00  000001   9.15  1000.0  Order_1U83YHJL   \n",
      "3   2017-01-10 09:31:00  000001   9.15  1000.0  Order_1FE7rxXC   \n",
      "4   2017-01-11 09:31:00  000001   9.14 -1000.0  Order_T5XO1nHW   \n",
      "5   2017-01-11 09:31:00  000004  42.45  1000.0  Order_pog7K9F1   \n",
      "6   2017-01-12 09:31:00  000001   9.15 -1000.0  Order_W06o9Ilz   \n",
      "7   2017-01-12 09:31:00  000004  42.05 -1000.0  Order_VGLT1B9e   \n",
      "8   2017-01-13 09:31:00  000007  23.81  1000.0  Order_GUiOhWtV   \n",
      "9   2017-01-16 09:31:00  000002  21.00  1000.0  Order_59tlRFmb   \n",
      "10  2017-01-17 09:31:00  000002  20.80 -1000.0  Order_lqFE27Lx   \n",
      "11  2017-01-17 09:31:00  000004  37.37  1000.0  Order_5pKx0uSo   \n",
      "12  2017-01-18 09:31:00  000001   9.17  1000.0  Order_wlNL0j1f   \n",
      "13  2017-01-18 09:31:00  000004  37.15  1000.0  Order_gDME90JG   \n",
      "14  2017-01-19 09:31:00  000001   9.18 -1000.0  Order_T9qMbBfh   \n",
      "15  2017-01-19 09:31:00  000004  35.69  1000.0  Order_pfGqWxQy   \n",
      "16  2017-01-20 09:31:00  000004  36.48 -1000.0  Order_YMlRe6aZ   \n",
      "17  2017-01-23 09:31:00  000002  20.74  1000.0  Order_6ZhPaDTi   \n",
      "18  2017-01-23 09:31:00  000004  37.56 -1000.0  Order_GopaSdIm   \n",
      "19  2017-01-24 09:31:00  000001   9.27  1000.0  Order_fcPZKAbI   \n",
      "20  2017-01-24 09:31:00  000002  20.69 -1000.0  Order_LhqpcEaN   \n",
      "21  2017-01-24 09:31:00  000004  38.63 -1000.0  Order_KW0FMjSA   \n",
      "22  2017-01-25 09:31:00  000001   9.26 -1000.0  Order_59AlaEgw   \n",
      "23  2017-01-25 09:31:00  000004  38.25  1000.0  Order_S3M0cJmV   \n",
      "24  2017-01-26 09:31:00  000004  38.29 -1000.0  Order_o0x8U143   \n",
      "\n",
      "          trade_id  commission    tax  \n",
      "0   Trade_QxUTrVs2      39.150   0.00  \n",
      "1   Trade_Mv40CGKI      39.360  26.24  \n",
      "2   Trade_gj487URw      13.725   0.00  \n",
      "3   Trade_XUCSG6iE      13.725   0.00  \n",
      "4   Trade_Zc0PGizg      13.710   9.14  \n",
      "5   Trade_JHay7AR5      63.675   0.00  \n",
      "6   Trade_iraNkGeX      13.725   9.15  \n",
      "7   Trade_FM0K8E1s      63.075  42.05  \n",
      "8   Trade_qyfrQO98      35.715   0.00  \n",
      "9   Trade_rKRw4NSC      31.500   0.00  \n",
      "10  Trade_O3hN6fpx      31.200  20.80  \n",
      "11  Trade_oDJr93xf      56.055   0.00  \n",
      "12  Trade_PsVcY7C2      13.755   0.00  \n",
      "13  Trade_KNeEQUWH      55.725   0.00  \n",
      "14  Trade_Jvem2dsj      13.770   9.18  \n",
      "15  Trade_7fvEs2tO      53.535   0.00  \n",
      "16  Trade_BRjrq1sa      54.720  36.48  \n",
      "17  Trade_ZnlUfDxM      31.110   0.00  \n",
      "18  Trade_fw1cDdT4      56.340  37.56  \n",
      "19  Trade_NA96r0IQ      13.905   0.00  \n",
      "20  Trade_xUCmrLia      31.035  20.69  \n",
      "21  Trade_YGKZ2k7o      57.945  38.63  \n",
      "22  Trade_sjVLtcdY      13.890   9.26  \n",
      "23  Trade_N2dHZG9o      57.375   0.00  \n",
      "24  Trade_JCPUeGtq      57.435  38.29  \n",
      "code\n",
      "000001       0.0\n",
      "000002       0.0\n",
      "000004       0.0\n",
      "000007    1000.0\n",
      "Name: amount, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "market.start()\n",
    "market.connect(QA.RUNNING_ENVIRONMENT.BACKETEST)\n",
    "\n",
    "# 打印market\n",
    "print(market)\n",
    "\n",
    "\n",
    "\"\"\"\n",
    "登陆到这个交易前置上 把你刚才的两个账户\n",
    "\"\"\"\n",
    "# 登陆交易\n",
    "market.login(QA.BROKER_TYPE.BACKETEST, a_1.account_cookie, a_1)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "for date in QA.QA_util_get_trade_range('2017-01-01','2017-01-31'):\n",
    "    for code in ['000001', '000002', '000004', '000007']:\n",
    "        if random.random()<0.3:\n",
    "            market.insert_order(account_id=a_1.account_cookie, amount=1000, price=None, amount_model=QA.AMOUNT_MODEL.BY_AMOUNT, time=date, code=code,\n",
    "                                order_model=QA.ORDER_MODEL.CLOSE, towards=QA.ORDER_DIRECTION.BUY, market_type=QA.MARKET_TYPE.STOCK_CN,\n",
    "                                frequence=QA.FREQUENCE.DAY, broker_name=QA.BROKER_TYPE.BACKETEST)\n",
    "        else:\n",
    "            try:\n",
    "                print(user.get_account(a_1.account_cookie).sell_available.get(code,0))\n",
    "                market.insert_order(account_id=a_1.account_cookie, amount=1000, price=None, amount_model=QA.AMOUNT_MODEL.BY_AMOUNT, time=date, code=code,\n",
    "                                    order_model=QA.ORDER_MODEL.CLOSE, towards=QA.ORDER_DIRECTION.SELL, market_type=QA.MARKET_TYPE.STOCK_CN,\n",
    "                                    frequence=QA.FREQUENCE.DAY, broker_name=QA.BROKER_TYPE.BACKETEST)\n",
    "            except:\n",
    "                pass\n",
    "    \n",
    "    market._settle(QA.BROKER_TYPE.BACKETEST)\n",
    "        \n",
    "\n",
    "print(a_1.history)\n",
    "print(a_1.cash)\n",
    "print(a_1.cash_available)\n",
    "print(a_1.history_table)\n",
    "print(a_1.hold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>order_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-01-03 09:31:00</td>\n",
       "      <td>000007</td>\n",
       "      <td>26.10</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_3Rg6u9PY</td>\n",
       "      <td>Trade_QxUTrVs2</td>\n",
       "      <td>39.150</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-01-05 09:31:00</td>\n",
       "      <td>000007</td>\n",
       "      <td>26.24</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_ckyKHpvZ</td>\n",
       "      <td>Trade_Mv40CGKI</td>\n",
       "      <td>39.360</td>\n",
       "      <td>26.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-01-09 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_1U83YHJL</td>\n",
       "      <td>Trade_gj487URw</td>\n",
       "      <td>13.725</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01-10 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_1FE7rxXC</td>\n",
       "      <td>Trade_XUCSG6iE</td>\n",
       "      <td>13.725</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-01-11 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.14</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_T5XO1nHW</td>\n",
       "      <td>Trade_Zc0PGizg</td>\n",
       "      <td>13.710</td>\n",
       "      <td>9.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-01-11 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>42.45</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_pog7K9F1</td>\n",
       "      <td>Trade_JHay7AR5</td>\n",
       "      <td>63.675</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2017-01-12 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.15</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_W06o9Ilz</td>\n",
       "      <td>Trade_iraNkGeX</td>\n",
       "      <td>13.725</td>\n",
       "      <td>9.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2017-01-12 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>42.05</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_VGLT1B9e</td>\n",
       "      <td>Trade_FM0K8E1s</td>\n",
       "      <td>63.075</td>\n",
       "      <td>42.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2017-01-13 09:31:00</td>\n",
       "      <td>000007</td>\n",
       "      <td>23.81</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_GUiOhWtV</td>\n",
       "      <td>Trade_qyfrQO98</td>\n",
       "      <td>35.715</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2017-01-16 09:31:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>21.00</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_59tlRFmb</td>\n",
       "      <td>Trade_rKRw4NSC</td>\n",
       "      <td>31.500</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2017-01-17 09:31:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.80</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_lqFE27Lx</td>\n",
       "      <td>Trade_O3hN6fpx</td>\n",
       "      <td>31.200</td>\n",
       "      <td>20.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2017-01-17 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.37</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_5pKx0uSo</td>\n",
       "      <td>Trade_oDJr93xf</td>\n",
       "      <td>56.055</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2017-01-18 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.17</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_wlNL0j1f</td>\n",
       "      <td>Trade_PsVcY7C2</td>\n",
       "      <td>13.755</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2017-01-18 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_gDME90JG</td>\n",
       "      <td>Trade_KNeEQUWH</td>\n",
       "      <td>55.725</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2017-01-19 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.18</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_T9qMbBfh</td>\n",
       "      <td>Trade_Jvem2dsj</td>\n",
       "      <td>13.770</td>\n",
       "      <td>9.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2017-01-19 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>35.69</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_pfGqWxQy</td>\n",
       "      <td>Trade_7fvEs2tO</td>\n",
       "      <td>53.535</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2017-01-20 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>36.48</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_YMlRe6aZ</td>\n",
       "      <td>Trade_BRjrq1sa</td>\n",
       "      <td>54.720</td>\n",
       "      <td>36.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2017-01-23 09:31:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.74</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_6ZhPaDTi</td>\n",
       "      <td>Trade_ZnlUfDxM</td>\n",
       "      <td>31.110</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2017-01-23 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.56</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_GopaSdIm</td>\n",
       "      <td>Trade_fw1cDdT4</td>\n",
       "      <td>56.340</td>\n",
       "      <td>37.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.27</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_fcPZKAbI</td>\n",
       "      <td>Trade_NA96r0IQ</td>\n",
       "      <td>13.905</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.69</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_LhqpcEaN</td>\n",
       "      <td>Trade_xUCmrLia</td>\n",
       "      <td>31.035</td>\n",
       "      <td>20.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>38.63</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_KW0FMjSA</td>\n",
       "      <td>Trade_YGKZ2k7o</td>\n",
       "      <td>57.945</td>\n",
       "      <td>38.63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2017-01-25 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.26</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_59AlaEgw</td>\n",
       "      <td>Trade_sjVLtcdY</td>\n",
       "      <td>13.890</td>\n",
       "      <td>9.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2017-01-25 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>38.25</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_S3M0cJmV</td>\n",
       "      <td>Trade_N2dHZG9o</td>\n",
       "      <td>57.375</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2017-01-26 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>38.29</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_o0x8U143</td>\n",
       "      <td>Trade_JCPUeGtq</td>\n",
       "      <td>57.435</td>\n",
       "      <td>38.29</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               datetime    code  price  amount        order_id  \\\n",
       "0   2017-01-03 09:31:00  000007  26.10  1000.0  Order_3Rg6u9PY   \n",
       "1   2017-01-05 09:31:00  000007  26.24 -1000.0  Order_ckyKHpvZ   \n",
       "2   2017-01-09 09:31:00  000001   9.15  1000.0  Order_1U83YHJL   \n",
       "3   2017-01-10 09:31:00  000001   9.15  1000.0  Order_1FE7rxXC   \n",
       "4   2017-01-11 09:31:00  000001   9.14 -1000.0  Order_T5XO1nHW   \n",
       "5   2017-01-11 09:31:00  000004  42.45  1000.0  Order_pog7K9F1   \n",
       "6   2017-01-12 09:31:00  000001   9.15 -1000.0  Order_W06o9Ilz   \n",
       "7   2017-01-12 09:31:00  000004  42.05 -1000.0  Order_VGLT1B9e   \n",
       "8   2017-01-13 09:31:00  000007  23.81  1000.0  Order_GUiOhWtV   \n",
       "9   2017-01-16 09:31:00  000002  21.00  1000.0  Order_59tlRFmb   \n",
       "10  2017-01-17 09:31:00  000002  20.80 -1000.0  Order_lqFE27Lx   \n",
       "11  2017-01-17 09:31:00  000004  37.37  1000.0  Order_5pKx0uSo   \n",
       "12  2017-01-18 09:31:00  000001   9.17  1000.0  Order_wlNL0j1f   \n",
       "13  2017-01-18 09:31:00  000004  37.15  1000.0  Order_gDME90JG   \n",
       "14  2017-01-19 09:31:00  000001   9.18 -1000.0  Order_T9qMbBfh   \n",
       "15  2017-01-19 09:31:00  000004  35.69  1000.0  Order_pfGqWxQy   \n",
       "16  2017-01-20 09:31:00  000004  36.48 -1000.0  Order_YMlRe6aZ   \n",
       "17  2017-01-23 09:31:00  000002  20.74  1000.0  Order_6ZhPaDTi   \n",
       "18  2017-01-23 09:31:00  000004  37.56 -1000.0  Order_GopaSdIm   \n",
       "19  2017-01-24 09:31:00  000001   9.27  1000.0  Order_fcPZKAbI   \n",
       "20  2017-01-24 09:31:00  000002  20.69 -1000.0  Order_LhqpcEaN   \n",
       "21  2017-01-24 09:31:00  000004  38.63 -1000.0  Order_KW0FMjSA   \n",
       "22  2017-01-25 09:31:00  000001   9.26 -1000.0  Order_59AlaEgw   \n",
       "23  2017-01-25 09:31:00  000004  38.25  1000.0  Order_S3M0cJmV   \n",
       "24  2017-01-26 09:31:00  000004  38.29 -1000.0  Order_o0x8U143   \n",
       "\n",
       "          trade_id  commission    tax  \n",
       "0   Trade_QxUTrVs2      39.150   0.00  \n",
       "1   Trade_Mv40CGKI      39.360  26.24  \n",
       "2   Trade_gj487URw      13.725   0.00  \n",
       "3   Trade_XUCSG6iE      13.725   0.00  \n",
       "4   Trade_Zc0PGizg      13.710   9.14  \n",
       "5   Trade_JHay7AR5      63.675   0.00  \n",
       "6   Trade_iraNkGeX      13.725   9.15  \n",
       "7   Trade_FM0K8E1s      63.075  42.05  \n",
       "8   Trade_qyfrQO98      35.715   0.00  \n",
       "9   Trade_rKRw4NSC      31.500   0.00  \n",
       "10  Trade_O3hN6fpx      31.200  20.80  \n",
       "11  Trade_oDJr93xf      56.055   0.00  \n",
       "12  Trade_PsVcY7C2      13.755   0.00  \n",
       "13  Trade_KNeEQUWH      55.725   0.00  \n",
       "14  Trade_Jvem2dsj      13.770   9.18  \n",
       "15  Trade_7fvEs2tO      53.535   0.00  \n",
       "16  Trade_BRjrq1sa      54.720  36.48  \n",
       "17  Trade_ZnlUfDxM      31.110   0.00  \n",
       "18  Trade_fw1cDdT4      56.340  37.56  \n",
       "19  Trade_NA96r0IQ      13.905   0.00  \n",
       "20  Trade_xUCmrLia      31.035  20.69  \n",
       "21  Trade_YGKZ2k7o      57.945  38.63  \n",
       "22  Trade_sjVLtcdY      13.890   9.26  \n",
       "23  Trade_N2dHZG9o      57.375   0.00  \n",
       "24  Trade_JCPUeGtq      57.435  38.29  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "b=QA.QA_Risk(a_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000001       0.0\n",
       "000002       0.0\n",
       "000004       0.0\n",
       "000007    1000.0\n",
       "Name: amount, dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "      <th>000007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03 09:31:00</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05 09:31:00</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09 09:31:00</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10 09:31:00</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11 09:31:00</th>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12 09:31:00</th>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13 09:31:00</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16 09:31:00</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17 09:31:00</th>\n",
       "      <td>0.0</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18 09:31:00</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19 09:31:00</th>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20 09:31:00</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23 09:31:00</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24 09:31:00</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25 09:31:00</th>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26 09:31:00</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code                 000001  000002  000004  000007\n",
       "datetime                                           \n",
       "2017-01-03 09:31:00     0.0     0.0     0.0  1000.0\n",
       "2017-01-05 09:31:00     0.0     0.0     0.0 -1000.0\n",
       "2017-01-09 09:31:00  1000.0     0.0     0.0     0.0\n",
       "2017-01-10 09:31:00  1000.0     0.0     0.0     0.0\n",
       "2017-01-11 09:31:00 -1000.0     0.0  1000.0     0.0\n",
       "2017-01-12 09:31:00 -1000.0     0.0 -1000.0     0.0\n",
       "2017-01-13 09:31:00     0.0     0.0     0.0  1000.0\n",
       "2017-01-16 09:31:00     0.0  1000.0     0.0     0.0\n",
       "2017-01-17 09:31:00     0.0 -1000.0  1000.0     0.0\n",
       "2017-01-18 09:31:00  1000.0     0.0  1000.0     0.0\n",
       "2017-01-19 09:31:00 -1000.0     0.0  1000.0     0.0\n",
       "2017-01-20 09:31:00     0.0     0.0 -1000.0     0.0\n",
       "2017-01-23 09:31:00     0.0  1000.0 -1000.0     0.0\n",
       "2017-01-24 09:31:00  1000.0 -1000.0 -1000.0     0.0\n",
       "2017-01-25 09:31:00 -1000.0     0.0  1000.0     0.0\n",
       "2017-01-26 09:31:00     0.0     0.0 -1000.0     0.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.trade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "      <th>000007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000004  000007\n",
       "date                                      \n",
       "2017-01-03     0.0     0.0     0.0  1000.0\n",
       "2017-01-05     0.0     0.0     0.0     0.0\n",
       "2017-01-09  1000.0     0.0     0.0     0.0\n",
       "2017-01-10  2000.0     0.0     0.0     0.0\n",
       "2017-01-11  1000.0     0.0  1000.0     0.0\n",
       "2017-01-12     0.0     0.0     0.0     0.0\n",
       "2017-01-13     0.0     0.0     0.0  1000.0\n",
       "2017-01-16     0.0  1000.0     0.0  1000.0\n",
       "2017-01-17     0.0     0.0  1000.0  1000.0\n",
       "2017-01-18  1000.0     0.0  2000.0  1000.0\n",
       "2017-01-19     0.0     0.0  3000.0  1000.0\n",
       "2017-01-20     0.0     0.0  2000.0  1000.0\n",
       "2017-01-23     0.0  1000.0  1000.0  1000.0\n",
       "2017-01-24  1000.0     0.0     0.0  1000.0\n",
       "2017-01-25     0.0     0.0  1000.0  1000.0\n",
       "2017-01-26     0.0     0.0     0.0  1000.0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n",
      "QUANTAXIS>> code 000001 date 2017-01-27 price None order_model close amount_model by_amount\n"
     ]
    }
   ],
   "source": [
    "market.insert_order(account_id=a_1.account_cookie, amount=2000, price=None, amount_model=QA.AMOUNT_MODEL.BY_AMOUNT, time='2017-01-27', code='000001',\n",
    "                    order_model=QA.ORDER_MODEL.CLOSE, towards=QA.ORDER_DIRECTION.SELL, market_type=QA.MARKET_TYPE.STOCK_CN,\n",
    "                    frequence=QA.FREQUENCE.DAY, broker_name=QA.BROKER_TYPE.BACKETEST)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n"
     ]
    }
   ],
   "source": [
    "market._settle(QA.BROKER_TYPE.BACKETEST)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "      <th>000007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000004  000007\n",
       "date                                      \n",
       "2017-01-03     0.0     0.0     0.0  1000.0\n",
       "2017-01-05     0.0     0.0     0.0     0.0\n",
       "2017-01-09  1000.0     0.0     0.0     0.0\n",
       "2017-01-10  2000.0     0.0     0.0     0.0\n",
       "2017-01-11  1000.0     0.0  1000.0     0.0\n",
       "2017-01-12     0.0     0.0     0.0     0.0\n",
       "2017-01-13     0.0     0.0     0.0  1000.0\n",
       "2017-01-16     0.0  1000.0     0.0  1000.0\n",
       "2017-01-17     0.0     0.0  1000.0  1000.0\n",
       "2017-01-18  1000.0     0.0  2000.0  1000.0\n",
       "2017-01-19     0.0     0.0  3000.0  1000.0\n",
       "2017-01-20     0.0     0.0  2000.0  1000.0\n",
       "2017-01-23     0.0  1000.0  1000.0  1000.0\n",
       "2017-01-24  1000.0     0.0     0.0  1000.0\n",
       "2017-01-25     0.0     0.0  1000.0  1000.0\n",
       "2017-01-26     0.0     0.0     0.0  1000.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data=QA.QA_fetch_stock_day_adv(['000001','000002','000004','000007'],'2017-01-03','2017-01-26')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "      <th>000007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>9.16</td>\n",
       "      <td>20.73</td>\n",
       "      <td>44.45</td>\n",
       "      <td>26.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <td>9.16</td>\n",
       "      <td>20.85</td>\n",
       "      <td>44.70</td>\n",
       "      <td>26.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>9.17</td>\n",
       "      <td>20.93</td>\n",
       "      <td>44.44</td>\n",
       "      <td>26.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <td>9.13</td>\n",
       "      <td>20.64</td>\n",
       "      <td>43.96</td>\n",
       "      <td>25.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>9.15</td>\n",
       "      <td>20.66</td>\n",
       "      <td>43.01</td>\n",
       "      <td>25.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>9.15</td>\n",
       "      <td>20.58</td>\n",
       "      <td>43.25</td>\n",
       "      <td>24.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11</th>\n",
       "      <td>9.14</td>\n",
       "      <td>20.40</td>\n",
       "      <td>42.45</td>\n",
       "      <td>24.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <td>9.15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>42.05</td>\n",
       "      <td>24.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13</th>\n",
       "      <td>9.16</td>\n",
       "      <td>21.81</td>\n",
       "      <td>41.00</td>\n",
       "      <td>23.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16</th>\n",
       "      <td>9.14</td>\n",
       "      <td>21.00</td>\n",
       "      <td>38.26</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <td>9.15</td>\n",
       "      <td>20.80</td>\n",
       "      <td>37.37</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <td>9.17</td>\n",
       "      <td>20.92</td>\n",
       "      <td>37.15</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <td>9.18</td>\n",
       "      <td>20.60</td>\n",
       "      <td>35.69</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <td>9.22</td>\n",
       "      <td>20.68</td>\n",
       "      <td>36.48</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <td>9.22</td>\n",
       "      <td>20.74</td>\n",
       "      <td>37.56</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <td>9.27</td>\n",
       "      <td>20.69</td>\n",
       "      <td>38.63</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25</th>\n",
       "      <td>9.26</td>\n",
       "      <td>20.61</td>\n",
       "      <td>38.25</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26</th>\n",
       "      <td>9.33</td>\n",
       "      <td>20.68</td>\n",
       "      <td>38.29</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000004  000007\n",
       "date                                      \n",
       "2017-01-03    9.16   20.73   44.45   26.10\n",
       "2017-01-04    9.16   20.85   44.70   26.47\n",
       "2017-01-05    9.17   20.93   44.44   26.24\n",
       "2017-01-06    9.13   20.64   43.96   25.45\n",
       "2017-01-09    9.15   20.66   43.01   25.09\n",
       "2017-01-10    9.15   20.58   43.25   24.79\n",
       "2017-01-11    9.14   20.40   42.45   24.85\n",
       "2017-01-12    9.15     NaN   42.05   24.61\n",
       "2017-01-13    9.16   21.81   41.00   23.81\n",
       "2017-01-16    9.14   21.00   38.26     NaN\n",
       "2017-01-17    9.15   20.80   37.37     NaN\n",
       "2017-01-18    9.17   20.92   37.15     NaN\n",
       "2017-01-19    9.18   20.60   35.69     NaN\n",
       "2017-01-20    9.22   20.68   36.48     NaN\n",
       "2017-01-23    9.22   20.74   37.56     NaN\n",
       "2017-01-24    9.27   20.69   38.63     NaN\n",
       "2017-01-25    9.26   20.61   38.25     NaN\n",
       "2017-01-26    9.33   20.68   38.29     NaN"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "md=data.pivot('close')\n",
    "md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>order_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-01-03 09:31:00</td>\n",
       "      <td>000007</td>\n",
       "      <td>26.10</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_3Rg6u9PY</td>\n",
       "      <td>Trade_QxUTrVs2</td>\n",
       "      <td>39.150</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-01-05 09:31:00</td>\n",
       "      <td>000007</td>\n",
       "      <td>26.24</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_ckyKHpvZ</td>\n",
       "      <td>Trade_Mv40CGKI</td>\n",
       "      <td>39.360</td>\n",
       "      <td>26.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-01-09 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_1U83YHJL</td>\n",
       "      <td>Trade_gj487URw</td>\n",
       "      <td>13.725</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01-10 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_1FE7rxXC</td>\n",
       "      <td>Trade_XUCSG6iE</td>\n",
       "      <td>13.725</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-01-11 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.14</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_T5XO1nHW</td>\n",
       "      <td>Trade_Zc0PGizg</td>\n",
       "      <td>13.710</td>\n",
       "      <td>9.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-01-11 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>42.45</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_pog7K9F1</td>\n",
       "      <td>Trade_JHay7AR5</td>\n",
       "      <td>63.675</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2017-01-12 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.15</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_W06o9Ilz</td>\n",
       "      <td>Trade_iraNkGeX</td>\n",
       "      <td>13.725</td>\n",
       "      <td>9.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2017-01-12 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>42.05</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_VGLT1B9e</td>\n",
       "      <td>Trade_FM0K8E1s</td>\n",
       "      <td>63.075</td>\n",
       "      <td>42.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2017-01-13 09:31:00</td>\n",
       "      <td>000007</td>\n",
       "      <td>23.81</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_GUiOhWtV</td>\n",
       "      <td>Trade_qyfrQO98</td>\n",
       "      <td>35.715</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2017-01-16 09:31:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>21.00</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_59tlRFmb</td>\n",
       "      <td>Trade_rKRw4NSC</td>\n",
       "      <td>31.500</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2017-01-17 09:31:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.80</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_lqFE27Lx</td>\n",
       "      <td>Trade_O3hN6fpx</td>\n",
       "      <td>31.200</td>\n",
       "      <td>20.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2017-01-17 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.37</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_5pKx0uSo</td>\n",
       "      <td>Trade_oDJr93xf</td>\n",
       "      <td>56.055</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2017-01-18 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.17</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_wlNL0j1f</td>\n",
       "      <td>Trade_PsVcY7C2</td>\n",
       "      <td>13.755</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2017-01-18 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_gDME90JG</td>\n",
       "      <td>Trade_KNeEQUWH</td>\n",
       "      <td>55.725</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2017-01-19 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.18</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_T9qMbBfh</td>\n",
       "      <td>Trade_Jvem2dsj</td>\n",
       "      <td>13.770</td>\n",
       "      <td>9.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2017-01-19 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>35.69</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_pfGqWxQy</td>\n",
       "      <td>Trade_7fvEs2tO</td>\n",
       "      <td>53.535</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2017-01-20 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>36.48</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_YMlRe6aZ</td>\n",
       "      <td>Trade_BRjrq1sa</td>\n",
       "      <td>54.720</td>\n",
       "      <td>36.48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2017-01-23 09:31:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.74</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_6ZhPaDTi</td>\n",
       "      <td>Trade_ZnlUfDxM</td>\n",
       "      <td>31.110</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2017-01-23 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.56</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_GopaSdIm</td>\n",
       "      <td>Trade_fw1cDdT4</td>\n",
       "      <td>56.340</td>\n",
       "      <td>37.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.27</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_fcPZKAbI</td>\n",
       "      <td>Trade_NA96r0IQ</td>\n",
       "      <td>13.905</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.69</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_LhqpcEaN</td>\n",
       "      <td>Trade_xUCmrLia</td>\n",
       "      <td>31.035</td>\n",
       "      <td>20.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>38.63</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_KW0FMjSA</td>\n",
       "      <td>Trade_YGKZ2k7o</td>\n",
       "      <td>57.945</td>\n",
       "      <td>38.63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2017-01-25 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.26</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_59AlaEgw</td>\n",
       "      <td>Trade_sjVLtcdY</td>\n",
       "      <td>13.890</td>\n",
       "      <td>9.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2017-01-25 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>38.25</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Order_S3M0cJmV</td>\n",
       "      <td>Trade_N2dHZG9o</td>\n",
       "      <td>57.375</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2017-01-26 09:31:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>38.29</td>\n",
       "      <td>-1000.0</td>\n",
       "      <td>Order_o0x8U143</td>\n",
       "      <td>Trade_JCPUeGtq</td>\n",
       "      <td>57.435</td>\n",
       "      <td>38.29</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               datetime    code  price  amount        order_id  \\\n",
       "0   2017-01-03 09:31:00  000007  26.10  1000.0  Order_3Rg6u9PY   \n",
       "1   2017-01-05 09:31:00  000007  26.24 -1000.0  Order_ckyKHpvZ   \n",
       "2   2017-01-09 09:31:00  000001   9.15  1000.0  Order_1U83YHJL   \n",
       "3   2017-01-10 09:31:00  000001   9.15  1000.0  Order_1FE7rxXC   \n",
       "4   2017-01-11 09:31:00  000001   9.14 -1000.0  Order_T5XO1nHW   \n",
       "5   2017-01-11 09:31:00  000004  42.45  1000.0  Order_pog7K9F1   \n",
       "6   2017-01-12 09:31:00  000001   9.15 -1000.0  Order_W06o9Ilz   \n",
       "7   2017-01-12 09:31:00  000004  42.05 -1000.0  Order_VGLT1B9e   \n",
       "8   2017-01-13 09:31:00  000007  23.81  1000.0  Order_GUiOhWtV   \n",
       "9   2017-01-16 09:31:00  000002  21.00  1000.0  Order_59tlRFmb   \n",
       "10  2017-01-17 09:31:00  000002  20.80 -1000.0  Order_lqFE27Lx   \n",
       "11  2017-01-17 09:31:00  000004  37.37  1000.0  Order_5pKx0uSo   \n",
       "12  2017-01-18 09:31:00  000001   9.17  1000.0  Order_wlNL0j1f   \n",
       "13  2017-01-18 09:31:00  000004  37.15  1000.0  Order_gDME90JG   \n",
       "14  2017-01-19 09:31:00  000001   9.18 -1000.0  Order_T9qMbBfh   \n",
       "15  2017-01-19 09:31:00  000004  35.69  1000.0  Order_pfGqWxQy   \n",
       "16  2017-01-20 09:31:00  000004  36.48 -1000.0  Order_YMlRe6aZ   \n",
       "17  2017-01-23 09:31:00  000002  20.74  1000.0  Order_6ZhPaDTi   \n",
       "18  2017-01-23 09:31:00  000004  37.56 -1000.0  Order_GopaSdIm   \n",
       "19  2017-01-24 09:31:00  000001   9.27  1000.0  Order_fcPZKAbI   \n",
       "20  2017-01-24 09:31:00  000002  20.69 -1000.0  Order_LhqpcEaN   \n",
       "21  2017-01-24 09:31:00  000004  38.63 -1000.0  Order_KW0FMjSA   \n",
       "22  2017-01-25 09:31:00  000001   9.26 -1000.0  Order_59AlaEgw   \n",
       "23  2017-01-25 09:31:00  000004  38.25  1000.0  Order_S3M0cJmV   \n",
       "24  2017-01-26 09:31:00  000004  38.29 -1000.0  Order_o0x8U143   \n",
       "\n",
       "          trade_id  commission    tax  \n",
       "0   Trade_QxUTrVs2      39.150   0.00  \n",
       "1   Trade_Mv40CGKI      39.360  26.24  \n",
       "2   Trade_gj487URw      13.725   0.00  \n",
       "3   Trade_XUCSG6iE      13.725   0.00  \n",
       "4   Trade_Zc0PGizg      13.710   9.14  \n",
       "5   Trade_JHay7AR5      63.675   0.00  \n",
       "6   Trade_iraNkGeX      13.725   9.15  \n",
       "7   Trade_FM0K8E1s      63.075  42.05  \n",
       "8   Trade_qyfrQO98      35.715   0.00  \n",
       "9   Trade_rKRw4NSC      31.500   0.00  \n",
       "10  Trade_O3hN6fpx      31.200  20.80  \n",
       "11  Trade_oDJr93xf      56.055   0.00  \n",
       "12  Trade_PsVcY7C2      13.755   0.00  \n",
       "13  Trade_KNeEQUWH      55.725   0.00  \n",
       "14  Trade_Jvem2dsj      13.770   9.18  \n",
       "15  Trade_7fvEs2tO      53.535   0.00  \n",
       "16  Trade_BRjrq1sa      54.720  36.48  \n",
       "17  Trade_ZnlUfDxM      31.110   0.00  \n",
       "18  Trade_fw1cDdT4      56.340  37.56  \n",
       "19  Trade_NA96r0IQ      13.905   0.00  \n",
       "20  Trade_xUCmrLia      31.035  20.69  \n",
       "21  Trade_YGKZ2k7o      57.945  38.63  \n",
       "22  Trade_sjVLtcdY      13.890   9.26  \n",
       "23  Trade_N2dHZG9o      57.375   0.00  \n",
       "24  Trade_JCPUeGtq      57.435  38.29  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "      <th>datetime</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03 09:31:00</th>\n",
       "      <td>973861</td>\n",
       "      <td>2017-01-03 09:31:00</td>\n",
       "      <td>2017-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05 09:31:00</th>\n",
       "      <td>1.00006e+06</td>\n",
       "      <td>2017-01-05 09:31:00</td>\n",
       "      <td>2017-01-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09 09:31:00</th>\n",
       "      <td>990898</td>\n",
       "      <td>2017-01-09 09:31:00</td>\n",
       "      <td>2017-01-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10 09:31:00</th>\n",
       "      <td>981734</td>\n",
       "      <td>2017-01-10 09:31:00</td>\n",
       "      <td>2017-01-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11 09:31:00</th>\n",
       "      <td>990860</td>\n",
       "      <td>2017-01-11 09:31:00</td>\n",
       "      <td>2017-01-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11 09:31:00</th>\n",
       "      <td>948347</td>\n",
       "      <td>2017-01-11 09:31:00</td>\n",
       "      <td>2017-01-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12 09:31:00</th>\n",
       "      <td>957483</td>\n",
       "      <td>2017-01-12 09:31:00</td>\n",
       "      <td>2017-01-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12 09:31:00</th>\n",
       "      <td>999470</td>\n",
       "      <td>2017-01-12 09:31:00</td>\n",
       "      <td>2017-01-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13 09:31:00</th>\n",
       "      <td>975624</td>\n",
       "      <td>2017-01-13 09:31:00</td>\n",
       "      <td>2017-01-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16 09:31:00</th>\n",
       "      <td>954593</td>\n",
       "      <td>2017-01-16 09:31:00</td>\n",
       "      <td>2017-01-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17 09:31:00</th>\n",
       "      <td>975361</td>\n",
       "      <td>2017-01-17 09:31:00</td>\n",
       "      <td>2017-01-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17 09:31:00</th>\n",
       "      <td>937935</td>\n",
       "      <td>2017-01-17 09:31:00</td>\n",
       "      <td>2017-01-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18 09:31:00</th>\n",
       "      <td>928752</td>\n",
       "      <td>2017-01-18 09:31:00</td>\n",
       "      <td>2017-01-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18 09:31:00</th>\n",
       "      <td>891546</td>\n",
       "      <td>2017-01-18 09:31:00</td>\n",
       "      <td>2017-01-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19 09:31:00</th>\n",
       "      <td>900712</td>\n",
       "      <td>2017-01-19 09:31:00</td>\n",
       "      <td>2017-01-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19 09:31:00</th>\n",
       "      <td>864969</td>\n",
       "      <td>2017-01-19 09:31:00</td>\n",
       "      <td>2017-01-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20 09:31:00</th>\n",
       "      <td>901394</td>\n",
       "      <td>2017-01-20 09:31:00</td>\n",
       "      <td>2017-01-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23 09:31:00</th>\n",
       "      <td>880623</td>\n",
       "      <td>2017-01-23 09:31:00</td>\n",
       "      <td>2017-01-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23 09:31:00</th>\n",
       "      <td>918126</td>\n",
       "      <td>2017-01-23 09:31:00</td>\n",
       "      <td>2017-01-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24 09:31:00</th>\n",
       "      <td>908843</td>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>2017-01-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24 09:31:00</th>\n",
       "      <td>929501</td>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>2017-01-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24 09:31:00</th>\n",
       "      <td>968074</td>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>2017-01-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25 09:31:00</th>\n",
       "      <td>977320</td>\n",
       "      <td>2017-01-25 09:31:00</td>\n",
       "      <td>2017-01-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25 09:31:00</th>\n",
       "      <td>939012</td>\n",
       "      <td>2017-01-25 09:31:00</td>\n",
       "      <td>2017-01-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26 09:31:00</th>\n",
       "      <td>977245</td>\n",
       "      <td>2017-01-26 09:31:00</td>\n",
       "      <td>2017-01-26</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            cash             datetime        date\n",
       "datetime                                                         \n",
       "2017-01-03 09:31:00       973861  2017-01-03 09:31:00  2017-01-03\n",
       "2017-01-05 09:31:00  1.00006e+06  2017-01-05 09:31:00  2017-01-05\n",
       "2017-01-09 09:31:00       990898  2017-01-09 09:31:00  2017-01-09\n",
       "2017-01-10 09:31:00       981734  2017-01-10 09:31:00  2017-01-10\n",
       "2017-01-11 09:31:00       990860  2017-01-11 09:31:00  2017-01-11\n",
       "2017-01-11 09:31:00       948347  2017-01-11 09:31:00  2017-01-11\n",
       "2017-01-12 09:31:00       957483  2017-01-12 09:31:00  2017-01-12\n",
       "2017-01-12 09:31:00       999470  2017-01-12 09:31:00  2017-01-12\n",
       "2017-01-13 09:31:00       975624  2017-01-13 09:31:00  2017-01-13\n",
       "2017-01-16 09:31:00       954593  2017-01-16 09:31:00  2017-01-16\n",
       "2017-01-17 09:31:00       975361  2017-01-17 09:31:00  2017-01-17\n",
       "2017-01-17 09:31:00       937935  2017-01-17 09:31:00  2017-01-17\n",
       "2017-01-18 09:31:00       928752  2017-01-18 09:31:00  2017-01-18\n",
       "2017-01-18 09:31:00       891546  2017-01-18 09:31:00  2017-01-18\n",
       "2017-01-19 09:31:00       900712  2017-01-19 09:31:00  2017-01-19\n",
       "2017-01-19 09:31:00       864969  2017-01-19 09:31:00  2017-01-19\n",
       "2017-01-20 09:31:00       901394  2017-01-20 09:31:00  2017-01-20\n",
       "2017-01-23 09:31:00       880623  2017-01-23 09:31:00  2017-01-23\n",
       "2017-01-23 09:31:00       918126  2017-01-23 09:31:00  2017-01-23\n",
       "2017-01-24 09:31:00       908843  2017-01-24 09:31:00  2017-01-24\n",
       "2017-01-24 09:31:00       929501  2017-01-24 09:31:00  2017-01-24\n",
       "2017-01-24 09:31:00       968074  2017-01-24 09:31:00  2017-01-24\n",
       "2017-01-25 09:31:00       977320  2017-01-25 09:31:00  2017-01-25\n",
       "2017-01-25 09:31:00       939012  2017-01-25 09:31:00  2017-01-25\n",
       "2017-01-26 09:31:00       977245  2017-01-26 09:31:00  2017-01-26"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.cash_table\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "      <th>datetime</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03 09:31:00</th>\n",
       "      <td>973861</td>\n",
       "      <td>2017-01-03 09:31:00</td>\n",
       "      <td>2017-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05 09:31:00</th>\n",
       "      <td>1.00006e+06</td>\n",
       "      <td>2017-01-05 09:31:00</td>\n",
       "      <td>2017-01-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09 09:31:00</th>\n",
       "      <td>990898</td>\n",
       "      <td>2017-01-09 09:31:00</td>\n",
       "      <td>2017-01-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10 09:31:00</th>\n",
       "      <td>981734</td>\n",
       "      <td>2017-01-10 09:31:00</td>\n",
       "      <td>2017-01-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11 09:31:00</th>\n",
       "      <td>948347</td>\n",
       "      <td>2017-01-11 09:31:00</td>\n",
       "      <td>2017-01-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12 09:31:00</th>\n",
       "      <td>999470</td>\n",
       "      <td>2017-01-12 09:31:00</td>\n",
       "      <td>2017-01-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13 09:31:00</th>\n",
       "      <td>975624</td>\n",
       "      <td>2017-01-13 09:31:00</td>\n",
       "      <td>2017-01-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16 09:31:00</th>\n",
       "      <td>954593</td>\n",
       "      <td>2017-01-16 09:31:00</td>\n",
       "      <td>2017-01-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17 09:31:00</th>\n",
       "      <td>937935</td>\n",
       "      <td>2017-01-17 09:31:00</td>\n",
       "      <td>2017-01-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18 09:31:00</th>\n",
       "      <td>891546</td>\n",
       "      <td>2017-01-18 09:31:00</td>\n",
       "      <td>2017-01-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19 09:31:00</th>\n",
       "      <td>864969</td>\n",
       "      <td>2017-01-19 09:31:00</td>\n",
       "      <td>2017-01-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20 09:31:00</th>\n",
       "      <td>901394</td>\n",
       "      <td>2017-01-20 09:31:00</td>\n",
       "      <td>2017-01-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23 09:31:00</th>\n",
       "      <td>918126</td>\n",
       "      <td>2017-01-23 09:31:00</td>\n",
       "      <td>2017-01-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24 09:31:00</th>\n",
       "      <td>968074</td>\n",
       "      <td>2017-01-24 09:31:00</td>\n",
       "      <td>2017-01-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25 09:31:00</th>\n",
       "      <td>939012</td>\n",
       "      <td>2017-01-25 09:31:00</td>\n",
       "      <td>2017-01-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26 09:31:00</th>\n",
       "      <td>977245</td>\n",
       "      <td>2017-01-26 09:31:00</td>\n",
       "      <td>2017-01-26</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            cash             datetime        date\n",
       "datetime                                                         \n",
       "2017-01-03 09:31:00       973861  2017-01-03 09:31:00  2017-01-03\n",
       "2017-01-05 09:31:00  1.00006e+06  2017-01-05 09:31:00  2017-01-05\n",
       "2017-01-09 09:31:00       990898  2017-01-09 09:31:00  2017-01-09\n",
       "2017-01-10 09:31:00       981734  2017-01-10 09:31:00  2017-01-10\n",
       "2017-01-11 09:31:00       948347  2017-01-11 09:31:00  2017-01-11\n",
       "2017-01-12 09:31:00       999470  2017-01-12 09:31:00  2017-01-12\n",
       "2017-01-13 09:31:00       975624  2017-01-13 09:31:00  2017-01-13\n",
       "2017-01-16 09:31:00       954593  2017-01-16 09:31:00  2017-01-16\n",
       "2017-01-17 09:31:00       937935  2017-01-17 09:31:00  2017-01-17\n",
       "2017-01-18 09:31:00       891546  2017-01-18 09:31:00  2017-01-18\n",
       "2017-01-19 09:31:00       864969  2017-01-19 09:31:00  2017-01-19\n",
       "2017-01-20 09:31:00       901394  2017-01-20 09:31:00  2017-01-20\n",
       "2017-01-23 09:31:00       918126  2017-01-23 09:31:00  2017-01-23\n",
       "2017-01-24 09:31:00       968074  2017-01-24 09:31:00  2017-01-24\n",
       "2017-01-25 09:31:00       939012  2017-01-25 09:31:00  2017-01-25\n",
       "2017-01-26 09:31:00       977245  2017-01-26 09:31:00  2017-01-26"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "      <th>000007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000004  000007\n",
       "date                                      \n",
       "2017-01-03     0.0     0.0     0.0  1000.0\n",
       "2017-01-05     0.0     0.0     0.0     0.0\n",
       "2017-01-09  1000.0     0.0     0.0     0.0\n",
       "2017-01-10  2000.0     0.0     0.0     0.0\n",
       "2017-01-11  1000.0     0.0  1000.0     0.0\n",
       "2017-01-12     0.0     0.0     0.0     0.0\n",
       "2017-01-13     0.0     0.0     0.0  1000.0\n",
       "2017-01-16     0.0  1000.0     0.0  1000.0\n",
       "2017-01-17     0.0     0.0  1000.0  1000.0\n",
       "2017-01-18  1000.0     0.0  2000.0  1000.0\n",
       "2017-01-19     0.0     0.0  3000.0  1000.0\n",
       "2017-01-20     0.0     0.0  2000.0  1000.0\n",
       "2017-01-23     0.0  1000.0  1000.0  1000.0\n",
       "2017-01-24  1000.0     0.0     0.0  1000.0\n",
       "2017-01-25     0.0     0.0  1000.0  1000.0\n",
       "2017-01-26     0.0     0.0     0.0  1000.0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data=a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['000007', '000001', '000004', '000002']"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.history_table.code.unique().tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "      <th>000007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000004  000007\n",
       "date                                      \n",
       "2017-01-03     0.0     0.0     0.0  1000.0\n",
       "2017-01-05     0.0     0.0     0.0     0.0\n",
       "2017-01-09  1000.0     0.0     0.0     0.0\n",
       "2017-01-10  2000.0     0.0     0.0     0.0\n",
       "2017-01-11  1000.0     0.0  1000.0     0.0\n",
       "2017-01-12     0.0     0.0     0.0     0.0\n",
       "2017-01-13     0.0     0.0     0.0  1000.0\n",
       "2017-01-16     0.0  1000.0     0.0  1000.0\n",
       "2017-01-17     0.0     0.0  1000.0  1000.0\n",
       "2017-01-18  1000.0     0.0  2000.0  1000.0\n",
       "2017-01-19     0.0     0.0  3000.0  1000.0\n",
       "2017-01-20     0.0     0.0  2000.0  1000.0\n",
       "2017-01-23     0.0  1000.0  1000.0  1000.0\n",
       "2017-01-24  1000.0     0.0     0.0  1000.0\n",
       "2017-01-25     0.0     0.0  1000.0  1000.0\n",
       "2017-01-26     0.0     0.0     0.0  1000.0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "market_data=QA.QA_fetch_stock_day_adv(list(data.columns),data.index[0],data.index[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_DataStruct_Stock_day with 4 securities >"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "market_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['000001', '000002', '000007', '000004']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(set([item[1] for item in a_1.history]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "      <th>000007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000004  000007\n",
       "date                                      \n",
       "2017-01-03     0.0     0.0     0.0  1000.0\n",
       "2017-01-05     0.0     0.0     0.0     0.0\n",
       "2017-01-09  1000.0     0.0     0.0     0.0\n",
       "2017-01-10  2000.0     0.0     0.0     0.0\n",
       "2017-01-11  1000.0     0.0  1000.0     0.0\n",
       "2017-01-12     0.0     0.0     0.0     0.0\n",
       "2017-01-13     0.0     0.0     0.0  1000.0\n",
       "2017-01-16     0.0  1000.0     0.0  1000.0\n",
       "2017-01-17     0.0     0.0  1000.0  1000.0\n",
       "2017-01-18  1000.0     0.0  2000.0  1000.0\n",
       "2017-01-19     0.0     0.0  3000.0  1000.0\n",
       "2017-01-20     0.0     0.0  2000.0  1000.0\n",
       "2017-01-23     0.0  1000.0  1000.0  1000.0\n",
       "2017-01-24  1000.0     0.0     0.0  1000.0\n",
       "2017-01-25     0.0     0.0  1000.0  1000.0\n",
       "2017-01-26     0.0     0.0     0.0  1000.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2017-01-03         999961\n",
       "2017-01-04            NaN\n",
       "2017-01-05    1.00006e+06\n",
       "2017-01-06            NaN\n",
       "2017-01-09    1.00005e+06\n",
       "2017-01-10    1.00003e+06\n",
       "2017-01-11         999937\n",
       "2017-01-12         999470\n",
       "2017-01-13         999434\n",
       "2017-01-16         975593\n",
       "2017-01-17         975305\n",
       "2017-01-18         975016\n",
       "2017-01-19         972039\n",
       "2017-01-20         974354\n",
       "2017-01-23         976426\n",
       "2017-01-24         977344\n",
       "2017-01-25         977262\n",
       "2017-01-26         977245\n",
       "dtype: object"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(market_data.to_qfq().pivot('close')*a_1.daily_hold).sum(axis=1)+a_1.daily_cash.set_index('date').cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "r=QA.QA_Risk(a_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_DataStruct_Stock_day with 4 securities >"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.market_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2017-01-03     999960.850\n",
       "2017-01-04     999960.850\n",
       "2017-01-05    1000061.490\n",
       "2017-01-06    1000061.490\n",
       "2017-01-09    1000047.765\n",
       "2017-01-10    1000034.040\n",
       "2017-01-11     999936.655\n",
       "2017-01-12     999469.855\n",
       "2017-01-13     999434.140\n",
       "2017-01-16     975592.640\n",
       "2017-01-17     975305.385\n",
       "2017-01-18     975015.905\n",
       "2017-01-19     972038.600\n",
       "2017-01-20     974353.880\n",
       "2017-01-23     976426.430\n",
       "2017-01-24     977343.545\n",
       "2017-01-25     977262.280\n",
       "2017-01-26     977244.845\n",
       "dtype: float64"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
